<template>
	<view class="page-view">
		<navBarView></navBarView>
		<navBar navBarTitle='登录/注册' leftIconColor='#fff' navBarTitleColor='#fff' :rightIconType='1'
			@rightIconChange="openPopup"></navBar>
		<view class="hint-block">
			<view class="hint-en">Welcome to Carlton International Education</view>
			<view class="hint-zh">欢迎来到卡尔顿国际教育。</view>
		</view>
		<view class="content-info">
			<view style="height: 64rpx;"></view>
			<view class="item-option">
				<view class="left-txt">+86 |</view>
				<input class="input-class" v-model="loginParam.mobile" placeholder-class="pl" placeholder="请输入手机号码" />
			</view>
			<view class="item-option-two">
				<view class="code-input-option">
					<input class="input-class" v-model="loginParam.code" placeholder-class="pl" placeholder="请输入验证码" />
				</view>
				<view class="code-hint-option" @tap="getCode">
					{{tips}}
				</view>
			</view>
			<view @click="loginClick" class="btn">登录</view>
			<uv-code :seconds="seconds" ref="code" @change="codeChange"></uv-code>

		</view>

		<sumitPopup ref="submitPopupRef" :classifyArr='courseLst' @submitPopupChange='submitPopupChange'></sumitPopup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '',
				seconds: 60,
				loginParam: {
					mobile: '',
					code: '',
				},
				courseLst: [],
			}
		},
		methods: {
			loginClick() {
				uni.showLoading({
					title: '登录中'
				})
				this.$http('common.userLogin', {
					phone: this.loginParam.mobile,
					code: this.loginParam.code
				}).then(res => {
					if (res.code == 200) {
						this.$tools.showMsg('登录成功')
						uni.hideLoading()
						uni.setStorageSync('loginToken', true)
						uni.reLaunch({
							url:'/pages/index/index'
						})
					}else{
						this.$tools.showMsg(res.msg)
					}
				})
			},
			openPopup() {
				this.$refs.submitPopupRef.openPopup()
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (!this.loginParam.mobile) {
					return this.$tools.showMsg('您的手机号不能为空')
				}
				if (this.loginParam.mobile.length < 11) {
					return this.$tools.showMsg('请您填写正确的手机号')
				}
				if (this.$refs.code.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$http('common.userSendCode', {
						mobile: this.loginParam.mobile
					}).then(res => {
						uni.hideLoading();

						if (res.code == 200) {
							this.$tools.showMsg('验证码已发送')
							this.$refs.code.start();
						} else {
							this.$tools.showMsg(res.msg)
						}
					})
				} else {
					this.$tools.showMsg('验证码倒计时中')
				}
			},
			submitPopupChange(data) {
				uni.showLoading({
					title: '提交中'
				})
				this.$http('common.addSubmit', {
					...data,
					adminId: uni.getStorageSync('adminId')
				}).then(res => {
					if (res.code == 200) {
						this.$tools.showMsg('提交成功')
						uni.hideLoading()
						this.$refs.submitPopupRef.clearParam()
						this.$refs.submitPopupRef.closePopup()
						console.log('res======>', res)
					}
				})
			},
		}
	}
</script>
<style>
	page {
		background: #fff;
		height: 100vh;
	}
</style>
<style lang="scss">
	.page-view {
		background-image: url('../../static/public/loginBg.png');
		background-repeat: no-repeat;
		background-size: 100% 762rpx;
	}

	.hint-block {
		margin-left: 32rpx;
		margin-right: 32rpx;

		.hint-en {
			margin-top: 98rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: rgba(255, 255, 255, 0.4);
		}

		.hint-zh {
			margin-top: 8rpx;
			font-weight: 500;
			font-size: 52rpx;
			color: #FFFFFF;
		}
	}

	.pl {
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
	}

	.content-info {
		margin-top: 60rpx;
		border-radius: 48rpx 48rpx 0rpx 0rpx;
		padding-left: 32rpx;
		padding-right: 32rpx;
		background: #fff;

		.item-option {
			border-radius: 12rpx;
			display: flex;
			align-items: center;
			padding: 0 32rpx;
			background: #F4F6F8;
			height: 98rpx;

			.left-txt {
				flex: none;
				font-weight: 400;
				font-size: 28rpx;
				color: #8F8F8F;
			}

			.input-class {
				flex: auto;
				padding-left: 34rpx;
			}
		}

		.item-option-two {
			margin-top: 32rpx;
			display: flex;
			align-items: center;

			.code-input-option {
				width: 424rpx;
				height: 98rpx;
				background: #F4F6F8;
				border-radius: 12rpx;
				display: flex;
				align-items: center;

				.input-class {
					flex: auto;
					padding-left: 32rpx;
				}
			}

			.code-hint-option {
				margin-left: 32rpx;
				width: 230rpx;
				height: 98rpx;
				color: #999999;
				line-height: 98rpx;
				text-align: center;
				background: #F4F6F8;
				border-radius: 12rpx;
				font-size: 28rpx;
			}
		}
	}

	.btn {
		margin-top: 130rpx;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #209E9A;
		box-shadow: 0rpx 8rpx 22rpx 0rpx rgba(32, 158, 154, 0.36);
		border-radius: 56rpx;
		font-weight: 500;
		font-size: 36rpx;
		color: #FFFFFF;
	}
</style>